package model.domain;


import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "sprint", catalog = "scrum")
public class Sprint implements java.io.Serializable {

	/**
	 * Default serial version ID generated by Eclipse
	 */
	private static final long serialVersionUID = 1L;
	private Integer sprintID;
        private Project project;
	private int sprintNumber;
        private String objective;
	private Date Start;
	private Date End;
	private List<Product> productbacklogs;

	public Sprint() {
	}

	public Sprint(int sprintNumber, Project project) {
		this.sprintNumber = sprintNumber;
                this.project = project;
	}

	public Sprint(int sprintNumber, Project project, String objective, Date Start, Date End,
			List<Product> productbacklogs) {
		this.sprintNumber = sprintNumber;
                this.objective = objective;
                this.project = project;
		this.Start = Start;
		this.End = End;
		this.productbacklogs = productbacklogs;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "nSprintID", unique = true, nullable = false)
	public Integer getSprintID() {
		return this.sprintID;
	}

	public void setSprintID(Integer sprintID) {
		this.sprintID = sprintID;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nProjectID", nullable = false)
	public Project getProject() {
		return this.project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	@Column(name = "nSprintNumber", nullable = false)
	public int getSprintNumber() {
		return this.sprintNumber;
	}

	public void setSprintNumber(int sprintNumber) {
		this.sprintNumber = sprintNumber;
	}

	@Column(name = "cObjective", length = 50)
	public String getObjective() {
		return this.objective;
	}

	public void setObjective(String objective) {
		this.objective = objective;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dtStart", length = 19)
	public Date getStart() {
		return this.Start;
	}

	public void setStart(Date dtStart) {
		this.Start = dtStart;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dtEnd", length = 19)
	public Date getEnd() {
		return this.End;
	}

	public void setEnd(Date End) {
		this.End = End;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "sprint")
	public List<Product> getProductbacklogs() {
		return this.productbacklogs;
	}

	public void setProductbacklogs(List<Product> productbacklogs) {
		this.productbacklogs = productbacklogs;
	}


    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }
        final Sprint other = (Sprint) obj;
        if(this.sprintID == null){
            if(other.getSprintID() != null){
                return false;
            }
        } else if(!this.sprintID.equals(other.getSprintID())){
            return false;
        }
        return true;

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.sprintID != null ? this.sprintID.hashCode() : 0);
        hash = 47 * hash + (this.objective != null ? this.objective.hashCode() : 0);
        return hash;
    }
}
